package com.hz.wjy.service.impl;

import com.hz.wjy.helper.StringHelper;
import com.hz.wjy.mapper.UserMapper;
import com.hz.wjy.model.entity.UserEntity;
import com.hz.wjy.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public void addUser(String username, String realname, String schoolId, String password, int userType) {
        UserEntity userEntity = new UserEntity();
        userEntity.setUsername(username);
        userEntity.setRealname(realname);
        userEntity.setStudent_id(schoolId);
        userEntity.setUser_type(userType);

        String pwdSalt = UUID.randomUUID().toString().replace("-", "");
        String pwd = StringHelper.generateMD5(password + pwdSalt);
        userEntity.setPwd_salt(pwdSalt);
        userEntity.setPwd(pwd);

        userEntity.setPwd_valid_date(System.currentTimeMillis() + 7 * 24 * 60 * 60 * 1000);
        userEntity.setPwd_error_count(0);
        userEntity.setGrade_id(0);
        userEntity.setClass_id(0);

        userMapper.addUser(userEntity);
    }

    @Override
    public boolean login(String username, String password) {
        return false;
    }
}
